from flask import current_app, session, render_template
from flask import g
from info.models import User
from info.utile.commons import user_login_data
from .import news_blu
#新闻详情展示

#请求路径:/news/<int:news_id>
#请求路径: GET
#请求路径: news_id
#返回值: detail.html页面,用户data字典数据
@news_blu.route('/<int:news_id>')
@user_login_data
def news_details(news_id):

    #获取用户编号
    user_id = session.get("user_id")

    #查询用户对象
    user = None
    if user_id:
        try:
            user = User.query.get(user_id)
        except Exception as e:
            current_app.logger.error(e)

    #拼接数据,渲染到页面
    data = {
        "user_if": g.user.to_dict() if g.user else""

    }


    return render_template("news/detail.html",data=data)
